@extends("admin.frame_layout")
<?php $top_selected = "信息管理";$page_menu = "回复列表" ?>
@section('content')
    <div class="formbody">
        <div class="formtitle"><span>回复会员咨询</span></div>

        <form action="{{ route('admin.feedback.reply',['id' => $id]) }}" method="post" id="notices">
            {!! csrf_field() !!}

            {{--加载编辑器的容器--}}
            <div>
                <script name="content" id="content"
                        type="text/plain">{!! "" !!}</script>
            </div>
            <div style="clear: both;"></div>

            <input type="submit" class="btn" style="margin-top: 10px;" value="确认回复"/>
        </form>
        @foreach($feedback_reply as $item)

            <div class="feed-item">
                <div class="formtitle"><span>咨询内容</span><span>{{ date("Y-m-d H:i:s",$item->time) }}</span></div>
                <div class="feedback">
                    {{ $item->content }}
                </div>
                <div class="divider"><span>回复</span>
                    [ {{ $item->reply_time == null ? '无' : date('Y-m-d H:i:s',$item->reply_time) }} ]：
                </div>
                <div class="reply">
                    {!! $item->reply == null ? '无' : $item->reply !!}
                </div>
            </div><br/>

        @endforeach


        @include('admin.coms.fenye')
    </div>
@endsection

@section('footer')
    <script src="{{asset('admin/js/ueditor/ueditor.config.js')}}"></script>
    <script src="{{asset('admin/js/ueditor/ueditor.all.js')}}"></script>
    <script src="{{asset('admin/js/laydate/laydate.js')}}"></script>
    {{-- 实例化编辑器 --}}
    <script type="text/javascript">
        $(function () {
            laydate.skin("dahong"); //大红色日期选择皮肤

            //初始化编辑器
            var ue = UE.getEditor('content', {
                initialFrameHeight: 250
            });

            $("#notices").validate({
                rules: {
                    title: {
                        required: true,
                        maxlength: 100
                    },
                    start: {required: true},
                    end: {required: true}
                },
                errorPlacement: function (error, element) {
                    $(element).closest("form").find("i[for='" + element.attr("id") + "']").html(error);
                },
                submitHandler: function (form) {
                    if (ue.hasContents()) {
                        ajaxSub(form);
                    } else {
                        toastr["error"]("请填写回复内容！");
                    }
                }
            });

            /**
             * ajax提交请求
             */
            function ajaxSub(form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function showSuccess(data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{route('admin.feedback.edit',['id' => $id])}}";
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection
